﻿/*
 卷芯架  shelf_number
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

using System.Data; 
using CSharpConnectMySQL;
using Common;

namespace Dingding.Helper
{
    public class MatShelfNumber
    {

        /// <summary>
        /// 根据A线业务逻辑修正卷芯架号【001-199】
        /// </summary>
        /// <param name="ShelfNumber"></param>
        /// <returns></returns>
        public static string GetShelfNumberA_OK(string ShelfNumber)
        {
            string strResult = ShelfNumber;


            char[] chars = strResult.ToCharArray();
            int length = chars.Length;

           
            if (length == 3 )
            {
                //首位0识别，成，6或9；[第1位只能为0或1]


                if (chars[0] != '0' & strResult != "100")
                {
                    strResult = "0" + strResult.Substring(1, length - 1);
                } 
            } 
            
           else if (length == 2  )
            {
                ////1、少1位，首位0没有识别出来（主要是由于上一个线架遮挡了，当前线架所导致的）
                if (chars[0] != '0')  
                {
                    strResult = "0" + strResult; 
                }
            } 


            //2.多1位；
            if (length == 4 )
            {
                //4识别成44；
                if ((chars[0] == '0'))
                {
                    strResult = strResult.Replace("44", "4");
                }
            }



            return strResult;
        }


        /// <summary>
        /// 根据B线业务逻辑修正卷芯架号【200-300】
        /// </summary>
        /// <param name="ShelfNumber"></param>
        /// <returns></returns>
        public static string GetShelfNumberB_OK(string ShelfNumber)
        {
            string strResult = ShelfNumber;


            char[] chars = strResult.ToCharArray();
            int length = chars.Length;

            //首位0识别，成，6或9；
            if (length == 3  )
            {
                if (chars[0] != '2'
               && strResult != "056" //by add 20240525 用户用错线架【把了A线的线架号】
               && strResult != "028" //by add 20240525 用户用错线架 【把了A线的线架号】               
               )
                {
                    strResult = "2" + strResult.Substring(1, length - 1);
                } 
            }  
            else  if (length == 2)
            {
                ////首位2没有识别出来（主要是由于上一个线架遮挡了，当前线架所导致的）
                if ((chars[0] != '2'))
                {
                    strResult = "2" + strResult;
                }
            }

            //2.多1位；
            else if (length == 4 )
            {
                //4识别成44；
                if (chars[0] == '2')
                {
                    strResult = strResult.Replace("44", "4");
                }
            }



            return strResult;
        }


      


        /// <summary>
        /// 传入工序号、类型获取对应的卷芯架号编码【客户修改除外】
        /// </summary>
        /// <param name="ShelfNumber"></param>
        /// <returns></returns>
        public static string GetShelfNumber(string ip )
        {
            string strResult = "-1";

            //获取需要修改的记录；
            string sql = " select SHELF_NUMBER from tmm0001_ocr_wb "
                            + "  where ip = " + ip + "  "
                            + " and REC_CREATE_TIME > UNIX_TIMESTAMP(DATE_SUB(NOW(3), INTERVAL 30 SECOND)) * 1000 "
                            + " order by REC_CREATE_TIME desc "
                            ;
            DataSet dataSet = MySqlHelper2.GetDataSet(sql);
            if (dataSet.Tables.Count>0 && dataSet.Tables[0].Rows.Count >0)
            {
                strResult = dataSet.Tables[0].Rows[0][0].ToString();
            }

            return strResult;
        }

        

    }
}